function[cdf] = Empirical_CDF(data,threshold)
%%%% computes the CDF(threshold) = P(X <= threshold) for a given dataset

sorted = [sort(data),max(data)+1];   %last element avoids index problem with i in while loop.

thresh = min(threshold, max(data));
i=1;
while sorted(i) <= thresh,
    i = i+1;
end;

cdf = (i-1)/length(data);
